home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 6984 / 6984.xpi / chrome / lazarus.jar / content / template-save.js < prev    next >
Text File  |  2009-11-24  |  2KB  |  67 lines

  1.  
  2.  
  3. var gArgs = window.arguments[0];
  4.  
  5. //this is a modal dialog so we should be safe to use the openers getstring method
  6. //to translate strings.
  7. Lazarus.getString = Lazarus.getBrowser().Lazarus.getString;
  8.  
  9. /**
  10. */
  11. function init(){
  12.     moveToAlertPosition(); 
  13.     initTemplateNames();
  14.     //WYSIWYG and AJAX textarea cannot be autofilled at this time
  15.     if (gArgs.isTextarea || gArgs.isIframe){
  16.         Lazarus.$('template-autofill').disabled = true;
  17.         Lazarus.$('template-autofill').setAttribute("tooltiptext", Lazarus.getString("template.save.autofill.disabled"));
  18.     }
  19. }
  20.  
  21.  
  22. /**
  23. * fill the template-names menu with the known names.
  24. */
  25. function initTemplateNames(){
  26.     var menu = Lazarus.$('template-names');
  27.     for (var i=0; i<gArgs.templateNames.length; i++){
  28.         var name = gArgs.templateNames[i];
  29.         var menuitem = document.createElement("menuitem");
  30.         menuitem.setAttribute("value", name);
  31.         menuitem.setAttribute("label", name);
  32.         menu.appendChild(menuitem);
  33.     }
  34.     
  35.     //suggest a default name for this template.
  36.     Lazarus.$('template-name').value = gArgs.defaultName;
  37. }
  38.  
  39.  
  40.  
  41. /**
  42. * handle user selecting "save"
  43. */
  44. function onOK() {
  45.     
  46.     var templateName = Lazarus.trim(Lazarus.$('template-name').value);
  47.     if (!templateName){
  48.         alert(Lazarus.getString("template.save.template.name.required"));
  49.         //restore focus to textbox
  50.         Lazarus.$('template-name').select();
  51.         return false;
  52.     }
  53.     //confirm if we are overwriting a known form
  54.     else if (!Lazarus.inArray(templateName, gArgs.templateNames) || confirm(Lazarus.getString("template.save.confirm.overwrite", templateName))){
  55.         gArgs.templateName = templateName;
  56.         gArgs.autofill = Lazarus.$('template-autofill').checked;
  57.         return true;
  58.     }
  59.     //name is already used, end user hit "cancel" on confirm overwrite dialog
  60.     else {
  61.         //don't close the dialog
  62.         return false; 
  63.     }
  64. }
  65.  
  66.